﻿using FHJFPro.Enum;
using System;
using System.Collections.Generic;
using System.Text;

namespace FHJFPro.Base
{
    public class ResponseResultBase
    {
        /// <summary>
        /// 响应码
        /// </summary>
        public ResponseResultCode Code { get; set; }

        /// <summary>
        /// 响应信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 成功
        /// </summary>
        public bool Success => Code == ResponseResultCode.Succeed;

        /// <summary>
        /// 时间戳(毫秒)
        /// </summary>
        public long Timestamp { get; } = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;

        /// <summary>
        /// 响应成功
        /// </summary>
        public void IsSuccess(string message = "响应成功")
        {
            Message = message;
            Code = ResponseResultCode.Succeed;
        }

        /// <summary>
        /// 响应失败
        /// </summary>
        public void IsFailed(string message = "响应失败")
        {
            Message = message;
            Code = ResponseResultCode.Failed;
        }

        /// <summary>
        /// 响应失败
        /// </summary>
        public void IsFailed(Exception exception)
        {
            Message = exception.InnerException?.StackTrace;
            Code = ResponseResultCode.Failed;
        }
    }
    public class ResponseResult<T> : ResponseResultBase where T : class
    {
        /// <summary>
        /// 返回结果
        /// </summary>
        public T Result { get; set; }

        /// <summary>
        /// 响应成功
        /// </summary>
        public void IsSuccess(T result = null, string message = "响应成功")
        {
            Message = message;
            Code = ResponseResultCode.Succeed;
            Result = result;
        }
        /// <summary>
        /// 响应失败
        /// </summary>
        public void IsFailed(T result = null, string message = "响应失败")
        {
            Message = message;
            Code = ResponseResultCode.Failed;
            Result = result;
        }
    }
}
